export default {
	zipStr(e) {
		// console.log('zipStr', e);
		if (!e) {
			return ''
		}
		let symbol = '*';
		if (e.length === 11) {
			return e.replace(/(\d{3})\d{4}(\d{2})/, `$1${symbol}${symbol}${symbol}${symbol}$2`)
		} else if (e.length === 18 || e.length === 15) {
			return e.replace(/(\d{12}).*/, `$1${symbol}${symbol}${symbol}${symbol}`)
		} else if (e.length === 2) {
			return e.charAt(0) + "*"
		} else {
			return e.charAt(0) + "*" + e.charAt(e.length - 1);
		}
	},
	zipPoint(e) {
		if (e > 999999999) {
			return (e / 1000000000).toFixed(2) + 'g'
		} else if (e > 999999) {
			return (e / 1000000).toFixed(2) + 'm'
		} else if (e > 999) {
			return (e / 1000).toFixed(2) + 'k'
		} else {
			return e
		}
	},
	isValidEmail(e) {
		var regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
		return regex.test(e);
	},
	hasReqsnState(e) {
		let orderType = [{
			status: 0,
			name: '待付款',
			icon: 'pay',
			color: '#dd524d'
		}, {
			status: 1,
			name: '待发货',
			icon: 'receipt',
			color: '#f0ad4e'
		}, {
			status: 2,
			name: '待收货',
			icon: 'logistics',
			color: '#4cd964'
		}, {
			status: 3,
			name: '待评价',
			icon: 'prize',
			color: '#007aff'
		}, {
			status: 4,
			name: '已评价',
			icon: 'prize',
			color: '#8b00d1'
		}, {
			status: 5,
			name: '已退款',
			icon: 'prize',
			color: '#666'
		}]
		return orderType.find(item => item.status === e)
	},
	hasPayMent(e) {
		let payMent = [{
			text: '微信支付',
			value: 'wxpay',
			icon: 'payment-wechat',
			color: '#48AC35'
		}, {
			text: '钱包支付',
			value: 'wallet',
			icon: 'pay-fill',
			color: '#00b09b'
		}, {
			text: '红包抵扣',
			value: 'master',
			icon: 'lucky-money-fill',
			color: '#dd524d',
			desc: '仅部分商品支持红包抵扣'
		}, {
			text: '积分兑换',
			value: 'point',
			icon: 'funds-fill',
			color: '#007aff',
			desc: '仅部分商品支持红包抵扣'
		}, {
			text: '支付宝',
			value: 'zhifubao',
			icon: 'payment-alipay',
			color: '#4FA2E7',
			desc: '暂不支持'
		}]
		return payMent.find(item => item.value === e)
	},
	/**
	 * 随机主题
	 */
	hasFizzTheme() {
		let theme = ['purple', 'gray', 'sunset', 'ocean', 'forest', 'berry', 'midnight', 'autumn', 'mint',
			'lavender', 'coral'
		]
		const idx = Math.floor(Math.random() * theme.length)
		return theme[idx]
	},
	/**
	 * 正则提取用户ID
	 */
	hasRegexStaffID(urls) {
		let pattern = /staff=(\d+)/;
		return urls.match(pattern)[0].match(/\d+/)[0]
	},
	/**
	 * 正则验证手机号
	 * @param {Object} poneInput
	 */
	isPoneAvailable(poneInput) {
		var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
		if (!myreg.test(poneInput)) {
			return false;
		} else {
			return true;
		}
	},
	/**
	 * 正则验证金额
	 */
	isPlaceMoney(e) {
		return /^\d+(\.\d{1,2})?$/.test(e)
	},
	/**
	 * 首页视频推荐
	 */
	mpIndexGoodsVideoList: async (host, data) => {
		try {
			let response = await uni.request({
				url: host + '/weapps/video/',
				method: 'GET',
				header: {
					'content-type': 'application/json'
				},
				data: data
			})
			return response.data;
		} catch (e) {
			throw e;
		}
	},
	/**
	 * 首页相册推荐
	 */
	mpIndexGoodsPhotoList: async (host, data) => {
		try {
			let response = await uni.request({
				url: host + '/weapps/cover/',
				method: 'GET',
				header: {
					'content-type': 'application/json'
				},
				data: data
			})
			return response.data;
		} catch (e) {
			throw e;
		}
	},
	/**
	 * 商品分类查询
	 */
	mpGoodsModesList: async (host, data) => {
		try {
			let response = await uni.request({
				url: host + '/weapps/modes/',
				method: 'GET',
				header: {
					'content-type': 'application/json'
				},
				data: data
			})
			return response.data;
		} catch (e) {
			throw e;
		}
	},
	/**
	 * 通用GET方法-免认证
	 */
	allinpayMethodList: async (host, data) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'GET',
				header: {
					'content-type': 'application/json'
				},
				data: data
			})
			return response.data;
		} catch (e) {
			throw e;
		}
	},
	allinpayMethodRead: async (host, pk) => {
		try {
			let response = await uni.request({
				url: host + pk + '/',
				method: 'GET',
				header: {
					'content-type': 'application/json'
				}
			})
			return response.data;
		} catch (e) {
			throw e;
		}
	},
	allinpayMethodPost: async (host, data) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'POST',
				header: {
					'content-type': 'application/json'
				},
				data: data
			})
			return response.data;
		} catch (e) {
			throw e;
		}
	},
	/**
	 * 通用方法-带认证
	 */
	authenticatorList: async (host, token, data) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'GET',
				header: {
					'content-type': 'application/json',
					'authorization': token
				},
				data: data
			})
			return response.data;
		} catch (e) {
			throw e;
		}
	},
	authenticatorRead: async (host, token) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'GET',
				header: {
					'content-type': 'application/json',
					'authorization': token
				}
			})
			return response.data;
		} catch (e) {
			throw e;
		}
	},
	authenticatorPost: async (host, token, data) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'POST',
				header: {
					'content-type': 'application/json',
					'authorization': token
				},
				data: data
			})
			return response.data;
		} catch (e) {
			throw e;
		}
	},
	authenticatorPatch: async (host, token, data) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'PATCH',
				header: {
					'content-type': 'application/json',
					'authorization': token
				},
				data: data
			})
			return response.data;
		} catch (e) {
			throw e;
		}
	},
	authenticatorDelete: async (host, token) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'DELETE',
				header: {
					'content-type': 'application/json',
					'authorization': token
				}
			})
			return response.data;
		} catch (e) {
			throw e;
		}
	},
	/**
	 * 拉起微信支付			
	 */
	requestPayment(e, reqsn) {
		uni.requestPayment({
			provider: "wxpay",
			timeStamp: e.timeStamp,
			nonceStr: e.nonceStr,
			package: e.package,
			signType: e.signType,
			paySign: e.paySign,
			success(r) {
				console.log('支付成功', r);
				uni.redirectTo({
					url: '/pageb/reqsn/paystate?reqsn=' + reqsn
				})
			},
			fail(e) {
				console.log('支付失败', e);
				uni.redirectTo({
					url: '/pageb/reqsn/paystate?reqsn=' + reqsn
				})
			}
		})
	},
	/**
	 * 拉起微信支付同步
	 */
	requestPaymentSync(e) {
		return new Promise((resolve, reject) => {
			uni.requestPayment({
				provider: "wxpay",
				timeStamp: e.timeStamp,
				nonceStr: e.nonceStr,
				package: e.package,
				signType: e.signType,
				paySign: e.paySign,
				success: (res) => {
					resolve(res);
				},
				fail: (err) => {
					reject(err);
				}
			});
		});
	},
	/**
	 * 打印日志
	 */
	print(mode, title, e) {
		if (mode === 'dev') {
			console.log(title, e);
		}
	},
	/**
	 * 新get封装
	 */
	authenticatorOnList: async (host, token, data) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'GET',
				header: {
					'content-type': 'application/json',
					'authorization': token
				},
				data: data
			})
			if (response.data.rescode === 200) {
				return response.data.resmsg;
			} else {
				throw response.data
			}
		} catch (e) {
			throw e;
		}
	},
	authenticatorOnRead: async (host, token) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'GET',
				header: {
					'content-type': 'application/json',
					'authorization': token
				}
			})
			if (response.data.rescode === 200) {
				return response.data.resmsg;
			} else {
				throw response.data
			}
		} catch (e) {
			throw e;
		}
	},
	authenticatorOnPost: async (host, token, data) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'POST',
				header: {
					'content-type': 'application/json',
					'authorization': token
				},
				data: data
			})
			if (response.data.rescode === 200) {
				return response.data.resmsg;
			} else {
				throw response.data
			}
		} catch (e) {
			throw e;
		}
	},
	authenticatorOnPatch: async (host, token, data) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'PATCH',
				header: {
					'content-type': 'application/json',
					'authorization': token
				},
				data: data
			})
			if (response.data.rescode === 200) {
				return response.data.resmsg;
			} else {
				throw response.data
			}
		} catch (e) {
			throw e;
		}
	},
	authenticatorOnDelete: async (host, token) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'DELETE',
				header: {
					'content-type': 'application/json',
					'authorization': token
				}
			})
			if (response.data.rescode === 200) {
				return response.data.resmsg;
			} else {
				throw response.data
			}
		} catch (e) {
			throw e;
		}
	},
	/**
	 * 无认证
	 */
	httpRequestOnList: async (host, data) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'GET',
				header: {
					'content-type': 'application/json',
				},
				data: data
			})
			if (response.data.rescode === 200) {
				return response.data.resmsg;
			} else {
				throw response.data
			}
		} catch (e) {
			throw e;
		}
	},
	httpRequestOnRead: async (host) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'GET',
				header: {
					'content-type': 'application/json'
				}
			})
			if (response.data.rescode === 200) {
				return response.data.resmsg;
			} else {
				throw response.data
			}
		} catch (e) {
			throw e;
		}
	},
	httpRequestOnPost: async (host, data) => {
		try {
			let response = await uni.request({
				url: host,
				method: 'POST',
				header: {
					'content-type': 'application/json'
				},
				data: data
			})
			if (response.data.rescode === 200) {
				return response.data.resmsg;
			} else {
				throw response.data
			}
		} catch (e) {
			throw e;
		}
	},
	/**
	 * 同步请求-测试
	 */
	authenticatorSyncList(host, token, data) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: host,
				method: "GET",
				header: {
					'content-type': 'application/json',
					'authorization': token
				},
				success(res) {
					console.log(res);
					resolve('success')
				},
				fail(err) {
					reject('error')
				}
			})
		})
	}
}